package com.ztgf.order.api.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.CustomizeUtil;
import com.ztgf.common.utils.ExcelExport2;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.order.models.bo.*;
import com.ztgf.order.models.dto.OrderContractParamRelationDTO;
import com.ztgf.order.models.service.*;
import com.ztgf.order.models.vo.*;
import com.ztgf.pay.models.bo.PayBatchPrintBO;
import com.ztgf.pay.models.vo.PayBatchPrintVO;
import com.ztgf.shopping.models.service.shop.IShopAddressService;
import com.ztgf.sms.models.bo.SmsInfoBO;
import com.ztgf.sms.models.service.ISmsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 订单表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-03 15:32:26
 */

@RestController
@RequestMapping("/api/orderInfo")
@Slf4j
@Api(value = "OrderInfoApiController", tags = "订单表Api接口")
public class OrderInfoApiController {

    @DubboReference
    private IOrderInfoService orderInfoService;
    @DubboReference
    private IOrderCommodityRelationService orderCommodityRelationService;
    @DubboReference
    private IOrderCommodityService orderCommodityService;
    @DubboReference
    private IShopAddressService shopAddressService;
    @DubboReference
    private IOrderContractRelationService orderContractRelationService;
    @DubboReference
    private IOrderRightsProtectionService orderRightsProtectionService;
    @DubboReference
    private IOrderInvoiceService orderInvoiceService;
    @DubboReference
    private ISmsInfoService smsInfoService;
    @DubboReference
    private IOrderReturnExpirationDateService orderReturnExpirationDateService;
    @DubboReference
    private IOrderPaymentTypeService orderPaymentTypeService;

    @PostMapping(value = "/shoppingTrolleySettlement")
    @ApiOperation(value = "购物车处理", notes = "购物车处理")
    public Result<?> shoppingTrolleySettlement(String shopCartDataVOStr) {
        ShopCartDataBO shopCartDataBO = JSON.parseObject(shopCartDataVOStr, ShopCartDataBO.class);
        if (shopCartDataBO.getShopCardShopInfoBOList().size() <= 0) {
            return new Result<>(CodeEnum.SHOP_CART_SHOP);
        }
        return orderInfoService.getShopCardData(shopCartDataBO);
    }


    @PostMapping(value = "/placeOrder")
    @ApiOperation(value = "下单", notes = "下单")
    public Result<List<Long>> placeOrder(String orderDataBOStr) {
        log.info("orderDataBOStr======"+orderDataBOStr);
        OrderDataBO orderDataBO = JSON.parseObject(orderDataBOStr, OrderDataBO.class);

        log.info("orderDataBO======"+orderDataBO.toString());

        if (orderDataBO.getOrderShopInfoBOList().size() <= 0) {
            return new Result<>(CodeEnum.SHOP_CART_SHOP);
        }

        Long buyerShopId = orderDataBO.getBuyerShopId();
        if (null == buyerShopId) {
            return new Result<>(CodeEnum.SHOP_CART_NO_BUYER);
        }

        //自己不能购买自己的商品
        if (buyerShopId.equals(orderDataBO.getOrderShopInfoBOList().get(0).getShopId())) {
            return new Result<>(CodeEnum.SHOP_CART_NOT_MY_COMMODITY);
        }
        Result result = new Result<>();
        try {
            result = orderInfoService.createOrder(orderDataBO, null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return new Result<>((CodeEnum.FAIL));
        }
        return result;
    }

    @PostMapping(value = "/getOrderInfoByOrderId")
    @ApiOperation(value = "返回订单信息", notes = "返回订单信息")
    public Result<List<OrderInfoVO>> getOrderInfoByOrderId(String ids) {
        if (StringUtils.isEmpty(ids)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        List<OrderInfoVO> orderInfoVOList = orderInfoService.getOrderInfoByOrderId(ids);
        return new Result<>(orderInfoVOList);
    }

    /**
     * 待支付页面查询
     *
     * @param orderIds
     * @return
     */
    @PostMapping(value = "/getPayInfoByOrderIds")
    @ApiOperation(value = "待支付页面查询", notes = "待支付页面查询")
    public Result getPayInfoByOrderIds(String orderIds) {
        if (StringUtils.isEmpty(orderIds)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        Map<String, Object> map = orderInfoService.getPayInfoByOrderIds(orderIds);
        return new Result<>(map);
    }

    /**
     * 跳转支付页面
     *
     * @param orderIds
     * @return
     */
    @PostMapping(value = "/skipPay")
    @ApiOperation(value = "跳转支付页面", notes = "跳转支付页面")
    public Result<OrderPayPageVO> skipPay(String orderIds) {
        if (StringUtils.isEmpty(orderIds)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        OrderPayPageVO orderPayPageVO = orderInfoService.getSkipPay(orderIds);
        return new Result<>(orderPayPageVO);
    }

    /**
     * 更新支付状态
     *
     * @param orderPayInfoBO
     * @return
     */
    @PostMapping(value = "/orderPay")
    @ApiOperation(value = "订单支付", notes = "订单支付")
    public Result orderPay(OrderPayInfoBO orderPayInfoBO) {
        if (null == orderPayInfoBO.getOrderIds()) {
            return new Result<>(CodeEnum.FAIL_100002);
        }

        return orderInfoService.orderPay(orderPayInfoBO);
    }

    /**
     * 验证是否通过
     *
     * @param code 验证码
     * @return
     */
    @PostMapping(value = "/getVerifyPayCode")
    @ApiOperation(value = "订单支付验证码", notes = "订单支付验证码")
    public Result getVerifyPayCode(String code, String phoneNumber) {
        SmsInfoBO smsInfoBO = new SmsInfoBO();
        smsInfoBO.setMobile(phoneNumber);
        smsInfoBO.setContent(code);
        smsInfoBO.setCaptchaType(4);//支付验证码
        boolean captcha = smsInfoService.getCaptcha(smsInfoBO);
        if (captcha) {
            return new Result();
        }
        return new Result(CodeEnum.FAIL_Login_1004);
    }

//    /**
//     * 更新支付状态
//     *
//     * @param orderIds
//     * @return
//     */
//    @PostMapping(value = "/updatePaySuccess")
//    @ApiOperation(value = "支付成功", notes = "支付成功")
//    public Result updatePaySuccess(String orderIds) {
//        if (null == orderIds) {
//            return new Result<>(CodeEnum.FAIL_100002);
//        }
//        String[] orderIdArray = orderIds.split(",");
//        for (String s : orderIdArray) {
//            orderInfoService.updatePaySuccess(Long.parseLong(s));
//        }
//        return new Result<>();
//    }

    @PostMapping(value = "/updateOpenPublished")
    @ApiOperation(value = "开发票", notes = "开发票")
    public Result updateOpenPublished(OrderOpenInvoiceBO orderOpenInvoiceBO) {
        OrderInvoiceBO orderInvoiceBO = JSON.parseObject(orderOpenInvoiceBO.getOrderInvoiceBOStr(),
                OrderInvoiceBO.class);
        orderOpenInvoiceBO.setOrderInvoiceBO(orderInvoiceBO);
        if (null == orderOpenInvoiceBO.getOrderId()) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        if (null == orderOpenInvoiceBO.getInvoiceHeadId()) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        if (null == orderOpenInvoiceBO.getOrderInvoiceBO()) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        orderInvoiceService.updateByOrderInfo(orderOpenInvoiceBO);
        return new Result();
    }

//    /**
//     * 签署合同
//     *
//     * @param orderId 订单id
//     * @param type    1 买家签订 2卖家签订
//     * @return 合同地址
//     */
//    @PostMapping(value = "/updateSignOver")
//    @ApiOperation(value = "签署完成接口", notes = "签署完成接口")
//    public Result updateSignOver(Long orderId, int type) {
//        if (null == orderId) {
//            return new Result<>(CodeEnum.FAIL_100002);
//        }
//        return orderInfoService.signOver(orderId, type);
//    }

    /**
     * 确定订单
     *
     * @param orderIds    订单ids
     * @param signShopId  签署人店铺id
     * @param type        1单订单 2多订单
     * @param htmlStrList 合同内容
     * @return 合同地址
     */
    @PostMapping(value = "/sureOrder")
    @ApiOperation(value = "确定订单", notes = "确定订单")
    public Result<List<OrderContractVO>> sureOrder(String orderIds, Long signShopId, int type, String htmlStrList, String annex) {
        List<String> htmlList = JSON.parseArray(htmlStrList, String.class);
        if (StringUtils.isEmpty(orderIds)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        //TODO 检查订单是否存在询价并还未改价的订单
        boolean checkOrderIsInquiry = orderInfoService.checkOrderIsInquiry(orderIds);
        if (!checkOrderIsInquiry) {
            return new Result<>(CodeEnum.ORDER_SURE_ERROR);
        }
        List<byte[]> bytes = new ArrayList<>();
        for (String htmlStr : htmlList) {
            bytes.add(htmlStr.getBytes());
        }
        List<String> orderIdList = Arrays.asList(orderIds.split(","));
        if (orderIdList.size()>5){
            return new Result<>(CodeEnum.ORDER_NUM_ERROR);
        }
        List<OrderContractVO> orderContractVOList =  orderInfoService.newSureOrder(orderIds, signShopId, type, bytes, annex);
        return new Result<>(orderContractVOList);
    }

    /**
     * 获取订单合同页面列表
     *
     * @param shopId   签署人id
     * @param orderIds 订单ids
     * @param type     1单订单 2多订单
     * @param signType 1买家签订 2卖家签订
     * @return
     */
    @ApiOperation(value = "获取订单合同页面列表", notes = "获取订单合同页面列表")
    @PostMapping("/getListOrderContractInfo")
    public Result<List<OrderContractVO>> getListOrderContractInfo(Long shopId, String orderIds, int type,
                                                                  int signType) {
        List<OrderContractVO> orderContractVOList = null;
        try {
            orderContractVOList = orderInfoService.getOrderContarctInfo(shopId, orderIds, type, signType);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
        return new Result<>(orderContractVOList);
    }

    /**
     * 获取签署页面 根据订单id
     *
     * @param orderId    订单id
     * @param signShopId 签署人店铺id
     * @param type       1单订单 2多订单
     * @param orderIds   订单ids
     * @return
     */
    @ApiOperation(value = "获取签署页面 根据订单id", notes = "获取签署页面 根据订单id")
    @PostMapping("/getSignaturePage")
    public Result<String> getSignaturePage(Long orderId, Long signShopId, int type, String orderIds) {
        String signatureUrl = orderContractRelationService.getSignaturePage(orderId, signShopId, type, orderIds, null);
        return new Result<>(signatureUrl);
    }

    /**
     * 获取废弃签署页面 根据订单id
     *
     * @param orderId  订单id
     * @param shopId   店铺id
     * @param signType 1买家签订 2卖家签订
     * @return
     */
    @ApiOperation(value = "获取废弃签署页面  根据订单id", notes = "获取废弃签署页面  根据订单id")
    @PostMapping("/getAbandonSignaturePage")
    public Result<String> getAbandonSignaturePage(Long orderId, Long shopId, int signType) {
        String signatureUrl = orderContractRelationService.getAbandonSignaturePage(orderId, shopId, signType);
        return new Result<>(signatureUrl);
    }

    @PostMapping(value = "/queryGoodsPrice")
    @ApiOperation(value = "订单商品价格", notes = "订单商品价格")
    public Result queryGoodsPrice(@RequestBody List<OrderCommodityAttrBO> list) {
        List<OrderCommodityVO> goodsPrice = orderCommodityService.queryGoodsPrice(list);
        return new Result<>(goodsPrice);
    }

    @PostMapping(value = "/queryGoodsInvenwtoryNumber")
    @ApiOperation(value = "查询单个sku商品库存", notes = "查询单个sku商品库存")
    public Result queryGoodsInventoryNumber(Long goodsId, String attrIds) {
        Integer number = orderCommodityService.queryGoodsInventoryNumber(goodsId, attrIds);
        return new Result<>(number);
    }

    /**
     * 查看合同
     *
     * @param orderId
     * @return
     */
    @PostMapping(value = "/getContactUrl")
    @ApiOperation(value = "查看合同", notes = "查看合同")
    public Result<String> getContactUrl(Long orderId) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        String contractUrl = orderContractRelationService.getContractByOrderId(orderId);
        return new Result<>(contractUrl);
    }

    /**
     * 修改合同
     *
     * @param orderContractParamRelationDTOStr 合同内容
     * @param htmlStrList                      合同html内容
     * @return
     */
    @PostMapping(value = "/updateContactByOrderId")
    @ApiOperation(value = "修改合同", notes = "修改合同")
    public Result<String> updateContactByOrderId(String orderContractParamRelationDTOStr, String htmlStrList) throws IOException {
        OrderContractParamRelationDTO orderContractParamRelationDTO =
                JSON.parseObject(orderContractParamRelationDTOStr, OrderContractParamRelationDTO.class);
        if (null == orderContractParamRelationDTO) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        if (null == htmlStrList) {
            return new Result<>(CodeEnum.FAIL_100002);
        }

        Result<String> result = orderInfoService.updateContactByOrderId(orderContractParamRelationDTO, null,
                htmlStrList.getBytes());
        return result;
    }

    /**
     * 催促签订合同
     *
     * @param orderId
     * @return
     */
    @PostMapping(value = "/urgeSignContact")
    @ApiOperation(value = "催促签订合同", notes = "催促签订合同")
    public Result urgeSignContact(Long orderId, Long sellShopId) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        orderInfoService.urgeSignContact(orderId, sellShopId);
        return new Result();
    }

    /**
     * 生产完成
     *
     * @param orderId
     * @return
     */
    @PostMapping(value = "/productOver")
    @ApiOperation(value = "生产完成", notes = "生产完成")
    public Result productOver(Long orderId) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean b = orderInfoService.productOver(orderId);
        if (b) {
            return new Result();
        }
        return new Result<>(CodeEnum.FAIL_100001);
    }

    /**
     * 卖家或者买家维权
     *
     * @param orderId
     * @param type    0买家 1卖家
     * @return
     */
    @PostMapping(value = "/updateRightsProtection")
    @ApiOperation(value = "维权", notes = "维权")
    public Result updateRightsProtection(Long orderId, int type, String reason) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean b = orderInfoService.updateRightsProtection(orderId, type,reason);
        if (b) {
            return new Result();
        }
        return new Result<>(CodeEnum.FAIL_100060);
    }

    /**
     * 催促发货
     *
     * @param orderId
     * @return
     */
    @PostMapping(value = "/urgeShipments")
    @ApiOperation(value = "催促发货", notes = "催促发货")
    public Result urgeShipments(Long orderId, Long sellShopId) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        orderInfoService.urgeShipments(orderId, sellShopId);
        return new Result();
    }

    /**
     * 删除订单
     *
     * @param orderId 订单id
     * @param type    0 买家 1 卖家
     * @return
     */
    @PostMapping(value = "/deleteOrder")
    @ApiOperation(value = "删除订单", notes = "删除订单")
    public Result deleteOrder(Long orderId, int type) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean b = orderInfoService.deleteOrder(orderId, type);
        if (b) {
            return new Result();
        }
        return new Result<>(CodeEnum.FAIL_100001);
    }

    @PostMapping(value = "/getOrderDetailsById")
    @ApiOperation(value = "订单详情", notes = "订单详情")
    public Result<OrderDetailsVO> getOrderDetailsById(Long id) {
        if (id != null) {
            OrderDetailsVO details = orderInfoService.getOrderDetailsById(id);
            return new Result<>(details);
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }

    /**
     * 保存订单支付类型
     *
     * @param orderPaymentTypeBOStr 支付类型相关参数
     * @return
     */
    @PostMapping(value = "/saveOrUpdateOrderPaymentType")
    @ApiOperation(value = "保存订单付款类型", notes = "保存订单付款类型")
    public Result saveOrUpdateOrderPaymentType(String orderPaymentTypeBOStr) {
        OrderPaymentTypeBO orderPaymentTypeBO = JSON.parseObject(orderPaymentTypeBOStr, OrderPaymentTypeBO.class);
        if (null != orderPaymentTypeBO) {

            Result result = orderPaymentTypeService.saveOrUpdateOrderPaymentType(orderPaymentTypeBO);
            return result;
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }


    /**
     * 修改订单支付类型(买家确认)
     *
     * @param orderPaymentTypestr 支付类型相关参数
     * @return
     */
    @PostMapping(value = "/updateOrderPaymentType")
    @ApiOperation(value = "修改订单付款类型", notes = "修改订单付款类型")
    public Result updateOrderPaymentType(String orderPaymentTypestr) {
        List<OrderPaymentTypeVO> orderPaymentTypeVOList = JSON.parseArray(orderPaymentTypestr,OrderPaymentTypeVO.class);
        if(CustomizeUtil.listIsNotNull(orderPaymentTypeVOList)){
            Result result = orderPaymentTypeService.updateOrderPaymentType(orderPaymentTypeVOList);
            return result;
        }

        return new Result<>(CodeEnum.FAIL_100002);
    }

    /**
     * 获取修改订单支付类型
     *
     * @param id 订单id
     * @return
     */
    @PostMapping(value = "/getOrderPaymentType")
    @ApiOperation(value = "获取修改订单付款类型", notes = "获取修改订单付款类型")
    public Result<List<OrderPaymentTypeVO>> getOrderPaymentType(Long id) {
        List<OrderPaymentTypeVO> orderPaymentTypeVOList = orderPaymentTypeService.getOrderPaymentType(id);
        return new Result<>(orderPaymentTypeVOList);
    }

    /**
     * @param orderId 订单id
     * @param type    6买家 7卖家
     * @return
     */
    @PostMapping(value = "/updateCancelOrder")
    @ApiOperation(value = "取消订单", notes = "取消订单")
    public Result updateCancelOrder(Long orderId, int type,
                                    @RequestParam(value = "cancelReasonId", required = false) String cancelReasonId) {
        if (null == orderId) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        Result result = orderInfoService.cancelOrder(orderId, type, cancelReasonId);
//        if(result.getCode() == CodeEnum.SUCCESS.getCode()){//库存还原
//            orderCommodityRelationService.restoreCommodityStock(orderId);
//        }
        return result;
    }

    @PostMapping(value = "/queryListPage")
    @ApiOperation(value = "订单列表", notes = "订单列表")
    public Result<Page<OrderInfoPageListVO>> queryListPage(OrderInfoGoodsPageBO bo) {
        Page<OrderInfoPageListVO> page = orderInfoService.queryListPage(bo);
        return new Result<>(page);
    }

    @GetMapping(value = "/exportOrderList/{shopId}")
    @ApiOperation(value = "导出订单列表", notes = "导出订单列表")
    public void exportOrderList(HttpServletResponse response, @PathVariable Long shopId) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"订单编号", "订单状态", "商品名称", "店铺名称", "卖家名称", "收货人", "收货人电话", "收货地址", "单价",
                "数量", "商品总价", "改价优惠", "批发优惠", "会员折扣优惠", "实付金额", "下单时间", "付款时间", "发货时间", "配送方式", "物流公司", "物流单号",
                "物流联系方式", "发票类型", "开票信息", "发票寄送地址", "备注信息"};
        //查询订单
        List<ExportAdminOrderListVO> list = orderInfoService.queryExportAdminOrderList(shopId, "0", 10);
        ExcelExport2.export(response, list, attributeNames, "_订单");
    }

    @GetMapping(value = "/batchExportOrderList/{ids}/{type}/{purchaseOrderType}")
    @ApiOperation(value = "批量导出订单", notes = "批量导出订单")
    public void batchExportOrderList(HttpServletResponse response, @PathVariable String ids, @PathVariable Integer type,@PathVariable Integer purchaseOrderType) {
        // type:0买家，1卖家
        if (type.equals(1)) {
            //创建一个数组用于设置表头
            String[] attributeNames = new String[]{"订单编号", "订单状态", "商品名称", "买家名称", "卖家名称", "收货人", "收货人电话", "收货地址", "单价",
                    "数量", "商品总价", "改价优惠", "批发优惠", "会员折扣优惠", "实付金额", "下单时间", "全款支付时间", "发货时间","首款支付时间","尾款支付时间","签收时间", "配送方式", "物流公司", "物流单号",
                    "物流联系方式", "发票类型","发票状态", "开票信息", "发票寄送地址", "备注信息", "实付技术服务费", "预计技术服务费", "退款金额"};
            //查询订单
            List<ExportSellerOrderListVO> list = orderInfoService.queryExportSellerOrderList(null, ids, 10,purchaseOrderType);
            ExcelExport2.export(response, list, attributeNames, "_订单");
        } else {
            //创建一个数组用于设置表头
            String[] attributeNames = new String[]{"订单编号", "订单状态", "商品名称", "买家名称", "卖家名称", "收货人", "收货人电话", "收货地址", "单价",
                    "数量", "商品总价", "改价优惠", "批发优惠", "会员折扣优惠", "实付金额", "下单时间", "全款支付时间", "发货时间","首款支付时间","尾款支付时间","签收时间", "配送方式", "物流公司", "物流单号",
                    "物流联系方式", "发票类型","发票状态", "开票信息", "发票寄送地址", "备注信息", "退款金额","砍价退款服务费","砍价服务费"};
            //查询订单
            List<ExportBuyerOrderListVO> list = orderInfoService.queryBuyerOrderList(null, ids, 10,purchaseOrderType);
            ExcelExport2.export(response, list, attributeNames, "_订单");
        }
    }


    @PostMapping(value = "/extendOrderTime")
    @ApiOperation(value = "卖家延长发货倒计时,售后订单id", notes = "卖家延长发货倒计时,售后订单id")
    public Result<?> extendOrderTime(Long id, Integer time) {
        boolean flag = orderReturnExpirationDateService.extendOrderTime(id, time);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL);
    }

    /**
     * 根据订单ID查询电子回执单
     *
     * @param shopId  userId
     * @param orderId orderId
     * @return 回执单URL
     */
    @PostMapping("/printingElectronicReceipt")
    @ApiOperation(value = "打印电子回单",notes = "打印电子回单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId",value = "店铺ID",required = true,paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderId",value = "订单ID",required = true,paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "date",value = "订单日期格式字符串(yyyy-MM-dd HH:mm:ss)",required = true,paramType = "query", dataType = "String")
    })
    public Result<List<String>> printingElectronicReceipt(String orderId,String shopId,String date){
        Result<List<String>> result;
        if (StrUtils.isEmpty(shopId) || StrUtils.isEmpty(date) || StrUtils.isEmpty(orderId)) {
            result =  new Result<>(CodeEnum.FAIL);
            return result;
        }
        List<String> urls = orderInfoService.printingElectronicReceipt(orderId,shopId,date);

        if (urls.isEmpty()) {
            result =  new Result<>(CodeEnum.ELECTRONIC_RECEIPT_QUERY_FAILED);
        } else {
            result = new Result<>();
            result.setData(urls);
        }
        return result;
    }




    /**
     * 根据订单ID批量查询电子回执单
     *
     * @param str  批量打印回单BO
     * @return 回执单URL
     */
    @PostMapping("/printingBatchElectronicReceipt")
    @ApiOperation(value = "批量打印电子回单",notes = "批量打印电子回单")
    public Result<PayBatchPrintVO> printingBatchElectronicReceipt(String str){
        List<PayBatchPrintBO> list = JSONArray.parseArray(str, PayBatchPrintBO.class);
        PayBatchPrintVO urls = orderInfoService.printingBatchElectronicReceipt(list);
        return new Result<>(urls);
    }

    @PostMapping(value = "/saveAgreeBillPay")
    @ApiOperation(value = "同意票据支付", notes = "同意票据支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "订单id",required = true,paramType = "query", dataType = "Long"),
    })
    public Result saveAgreeBillPay(Long id) {
        return orderInfoService.saveAgreeBillPay(id);
    }

    @PostMapping(value = "/saveNoAgreeBillPay")
    @ApiOperation(value = "不同意票据支付", notes = "不同意票据支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "订单id",required = true,paramType = "query", dataType = "Long"),
    })
    public Result saveNoAgreeBillPay(Long id) {
        return orderInfoService.saveNoAgreeBillPay(id);
    }



    public static void main(String args[]){
        String str = "{\"buyerShopId\":\"451445837726351360\",\"OrderShopInfoBO\":[{\"shopId\":\"451508845852884992\",\"OrderCommodityBO\":[{\"commodityId\":\"637610241562902528\",\"attrIds\":\"\",\"commodityNum\":\"22\",\"discountsType\":0,\"availableArea\":\"0\",\"taxRate\":null,\"purchaseCommodityType\":1,\"purchaseCommodityBargainId\":\"639505264097230848\"}]}],\"payType\":0,\"type\":0,\"addressId\":null,\"areaId\":\"110101\",\"userAddress\":\"ahahah\",\"userName\":\"asd\",\"userMobile\":\"13568419577\",\"invoiceHeadId\":\"636898439971602432\",\"OrderInvoiceBO\":{\"id\":\"636898439971602432\",\"type\":0,\"receivingName\":\"asd\",\"mobile\":\"13568419577\",\"areaId\":\"110101\",\"invoiceContent\":\"北京市市辖区东城区ahahah\",\"receivingAddress\":\"ahahah\",\"invoiceType\":0,\"email\":\"\"},\"placeOrderType\":0}";
        OrderDataBO orderDataBO = JSON.parseObject(str, OrderDataBO.class);

        System.out.println(orderDataBO.toString());

    }
}
